﻿using Engine;
using Game;
using Mekiasm.Common;
namespace Mekiasm
{
    public class ChargePad : ComplexModelItem
    {
        public static int Index;
        public ChargePad() : base(new ModelItem[] {
            new ModelItem("port_led4", "ports_led"), new ModelItem("port_led3", "ports_led"), new ModelItem("port_led2", "ports_led"),
            new ModelItem("port_led1", "ports_led"), new ModelItem("port", "ports"), new ModelItem("plug", "chargepad"),
            new ModelItem("stand", "chargepad_elements"), new ModelItem("connector", "chargepad_elements"), new ModelItem("base", "chargepad"),
            new ModelItem("base", "bottom"), new ModelItem("pillar1", "chargepad_elements"), new ModelItem("pillar2", "chargepad_elements") }, "chargepad", "充电桩")
        {
            

        }
        public override bool OnUse(Ray3 aim, ComponentMiner componentMiner, TerrainRaycastResult? raycast)
        {
            return false;
        }
        public override MekBlock.DeviceType GetDeviceType()
        {
            return MekBlock.DeviceType.Electric;
        }
        public override bool OnInteract(SubsystemBlockBehavior blockBehavior, TerrainRaycastResult raycastResult, ComponentMiner componentMiner)
        {
            ComponentChargepad mcomponent = ILibrary.SubsystemBlockEntities.GetBlockEntity(raycastResult.CellFace.X, raycastResult.CellFace.Y, raycastResult.CellFace.Z).Entity.FindComponent<ComponentChargepad>(true);
            componentMiner.ComponentPlayer.ComponentGui.ModalPanelWidget = new BatBoxWidget(mcomponent, componentMiner, DisplayName);
            return true;
        }
        public override void OnBlockAdded(SubsystemBlockBehavior blockBehavior, int value, int oldValue, int x, int y, int z)
        {
            ILibrary.AddBaseEnergyEntity(DisplayName, x, y, z, null,
                ILibrary.GetRotetedConfig(value, new MachineFaceConfig[] {
            new MachineFaceConfig(MekBlock.MachineMode.IN,MekBlock.DeviceType.Electric),
            new MachineFaceConfig(),
            new MachineFaceConfig(),
            new MachineFaceConfig(),
            new MachineFaceConfig(),
            new MachineFaceConfig()
            }),new MachineAmountLimitConfig() { MaxPower=102400,OutputPowerLimit=32,InputPowerLimit=32});//1k eu电量
            ElectricSystem.Add(new ElectricElement.ChargepadElement(x, y, z));
        }
        public override void OnBlockGenerated(int value, int x, int y, int z, bool isLoaded)
        {
            ElectricSystem.Add(new ElectricElement.ChargepadElement(x, y, z));
        }
        public override void OnBlockRemoved(SubsystemBlockBehavior blockBehavior, int value, int newValue, int x, int y, int z)
        {
            ILibrary.RemoveBlockEntity(x, y, z);
            ElectricSystem.Remove(new Point3(x, y, z));
        }
    }
}
